package com.longe.netty.decoderAndEncoder;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class NettyServerHandler extends SimpleChannelInboundHandler<Long> {

    /**
     * 异常
     *
     * @param ctx
     * @param cause
     */
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        //关闭通道
        ctx.close();
    }

    /**
     * 读取信息
     *
     * @param ctx
     * @param msg
     */
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Long msg) {

        System.err.println("从客户端" + ctx.channel().remoteAddress() + " 读取到long = " + msg);
        //给客户端发送一个long
        ctx.writeAndFlush(98765L);
    }
}
